/**
 * 护理计划Service业务层处理
 * 
 * @author alexis
 * @date 2025-06-02
 */
@Service
public class NursingPlanServiceImpl extends ServiceImpl<NursingPlanMapper, NursingPlan> implements INursingPlanService
{
@Autowired
private NursingPlanMapper nursingPlanMapper;
    @Autowired
    private NursingProjectPlanMapper nursingProjectPlanMapper;

    @Override
    public PageResult<NursingPlan> getList(NursingPage nursingPage) {
        PageHelper.startPage(nursingPage.getPage(),nursingPage.getPageSize());
        List<NursingPlan> List = nursingPlanMapper.getlist(nursingPage);
        Page<NursingPlan> p = (Page<NursingPlan>) List;
        return new PageResult<>(p.getTotal(), List);
    }

    @Override
    @Transactional
    public Object insertNursingPlan(NursingPlanDto dto) {
        NursingPlan nursingPlan = new NursingPlan();
        BeanUtils.copyProperties(dto, nursingPlan);
        nursingPlan.setCreateTime(LocalDateTime.now());

        nursingPlanMapper.insert(nursingPlan);

        // 2.批量保存护理计划和护理项目的对应关系
        if (dto.getProjectPlans() != null && !dto.getProjectPlans().isEmpty()) {
            int count = nursingProjectPlanMapper.batchInsert(nursingPlan.getId(), dto.getProjectPlans());
            return count > 0 ? 1 : 0;
        }
        
        return 1;
    }


}